//
//  ClubMemberManVC.m
//  SelfDrivingTravelling-IOS
//
//  Created by Teplot_01 on 16/8/25.
//  Copyright © 2016年 Teplot_01. All rights reserved.
//

#import "ClubMemberManVC.h"

@interface ClubMemberManVC ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation ClubMemberManVC
{
    UITableView *_tableView;
    
    //请求下来的字典
    NSDictionary *_responseDic;
    //请求下来的数组
    NSArray *_responseArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = White_Color;
    self.title = @"会员管理";
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"search"] style:UIBarButtonItemStylePlain target:self action:@selector(searchBtnAction)];
    
    [self requestForMemberList];
    [self initTableViewWithMenberMan];
    //设置多余的分割线不显示
    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
- (void)initTableViewWithMenberMan{
    _tableView = [[UITableView alloc]initWithFrame:self.view.frame];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
}
#pragma - mark RequestForMemberList
- (void)requestForMemberList{
    //参数
    NSDictionary *parameters = @{
                                 @"clubID":[NSString readToNSDefaultsWithKey:kClubId],
                                 @"pageNum":@"1",
                                 @"pageSize":@"10",
                                 };
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager POST:@"http://115.28.152.130/tour/v1/club/clubUserList.action" parameters:parameters success:^(NSURLSessionDataTask *operation, id responseObject) {
        _responseDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
        NSLog(@"%@>>>>",_responseDic);
        _responseArr = _responseDic[@"list"];
        NSString *error = _responseDic[@"code"];
        if (![_responseDic[@"code"] isEqualToString:@"0000"]) {
            [SVProgressHUD showErrorWithStatus:[NSString errorStringWithCode:error]];
        }else{
            //请求成功
//            [SVProgressHUD showSuccessWithStatus:@"请求成功"];
            [_tableView reloadData];
        }
        
    } failure:^(NSURLSessionDataTask *operation, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求失败"];
    }];
}
#pragma - mark UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _responseArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]init];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    UIImageView *icon = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
    icon.layer.cornerRadius = 5;
    icon.layer.masksToBounds = YES;
    NSString *iconStr = _responseDic[@"list"][indexPath.row][@"photo"];
    [icon sd_setImageWithURL:[NSURL URLWithString:iconStr] placeholderImage:[UIImage imageNamed:@"userIcon"]];
    [cell.contentView addSubview:icon];
    UILabel *nameLb = [[UILabel alloc]initWithFrame:CGRectMake(70, 12, 100, 15)];
    nameLb.text = _responseDic[@"list"][indexPath.row][@"realName"];
    [cell.contentView addSubview:nameLb];
    UILabel *accountLb = [[UILabel alloc]initWithFrame:CGRectMake(70, 45, 150, 15)];
    accountLb.text = _responseDic[@"list"][indexPath.row][@"phone"];
    accountLb.font = [UIFont systemFontOfSize:13];
    accountLb.textColor = Gray_Color;
    [cell.contentView addSubview:accountLb];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 75;
}
//- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return UITableViewCellEditingStyleDelete;
//}
//-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
//    if (editingStyle==UITableViewCellEditingStyleDelete) {
//        //先删除数据源里面对应的数据
////        [rowCountArr removeObjectAtIndex:indexDelete];
////        rowCount--;
//        //再删除UI
////        [_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]  withRowAnimation:UITableViewRowAnimationFade];
////        [_tableView reloadData];
//    }
//}
//
- (void)searchBtnAction{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
